home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility2 / postman.zip / POSTMAN1.C < prev    next >
C/C++ Source or Header  |  1991-05-01  |  3KB  |  110 lines

  1. #include <windows.h>
  2. #include "postman1.h"
  3.  
  4. struct
  5.     {
  6.     BOOL    bColor;
  7.     int     nWindows,
  8.             nLevel;
  9.     HWINFO  hWinfo;
  10.     LPWINFO lpWinfo;
  11.     } ListStats = {FALSE, 0, 0, NULL, 0L};
  12.  
  13. static void winlist_enum  (HWND hwnd);
  14. static void winlist_count (HWND hwnd);
  15.  
  16.  
  17.  
  18.  
  19.  
  20. void winlist_enumAll (HWND hwnd)
  21.     {
  22.     HWND hwndFirst = GetWindow (hwnd, GW_HWNDFIRST);
  23.  
  24.     ListStats.nWindows   = 0;
  25.     ListStats.nLevel     = 0;
  26.     ListStats.bColor     = FALSE;
  27.     winlist_count (hwndFirst);
  28.  
  29.     if (ListStats.hWinfo) GlobalFree (ListStats.hWinfo);
  30.     ListStats.hWinfo  = (HWINFO)  GlobalAlloc (GMEM_MOVEABLE, ListStats.nWindows*sizeof(WINFO));
  31.     ListStats.lpWinfo = (LPWINFO) GlobalLock  (ListStats.hWinfo);
  32.     winlist_enum (hwndFirst);
  33.     GlobalUnlock (ListStats.hWinfo);
  34.     }
  35.  
  36.  
  37. static void winlist_count (HWND hwnd)
  38.      {
  39.      HWND hwndChild,
  40.           hwndSibling;
  41.  
  42.      ListStats.nWindows++;
  43.  
  44.      if (hwndChild = GetWindow (hwnd, GW_CHILD))  // count children
  45.           winlist_count (hwndChild);
  46.  
  47.      if (hwndSibling = GetWindow(hwnd, GW_HWNDNEXT)) // count siblings
  48.           winlist_count (hwndSibling);
  49.      }
  50.  
  51.  
  52. static void winlist_enum (HWND hwnd)
  53.      {
  54.      HWND hwndChild,
  55.           hwndSibling;
  56.      int  nLength;
  57.  
  58.      GetClassName  (hwnd, ListStats.lpWinfo->szClassName, CLASSNAMEMAX);
  59.      ListStats.lpWinfo->szClassName [CLASSNAMEMAX - 1] = '\0';
  60.  
  61.      nLength = GetWindowText (hwnd, ListStats.lpWinfo->szTitle, WINDOWTITLEMAX);
  62.      ListStats.lpWinfo->szTitle [nLength] = '\0';
  63.  
  64.      ListStats.lpWinfo->hwnd    = hwnd;
  65.      ListStats.lpWinfo->hwndParent = GetParent (hwnd);
  66.      ListStats.lpWinfo->dwStyle = GetWindowLong (hwnd, GWL_STYLE);
  67.      ListStats.lpWinfo->bColor  = ListStats.bColor ;
  68.      ListStats.lpWinfo->nLevel  = ListStats.nLevel ;
  69.      ListStats.lpWinfo->hIcon   = GetClassWord (hwnd, GCW_HICON) ;
  70.      ListStats.lpWinfo++;
  71.  
  72.      if (hwndChild = GetWindow (hwnd, GW_CHILD))  // enum children
  73.           {
  74.           ListStats.nLevel++;
  75.           winlist_enum (hwndChild);
  76.           }
  77.  
  78.      if (hwndSibling = GetWindow (hwnd, GW_HWNDNEXT)) // enum siblings
  79.           {
  80.           if (GetWindowTask (hwndSibling) != GetWindowTask (hwnd))
  81.                {
  82.                ListStats.bColor = !ListStats.bColor;
  83.                }
  84.           winlist_enum (hwndSibling);
  85.           }
  86.      else
  87.           {
  88.           ListStats.nLevel--;
  89.           }
  90.      }
  91.  
  92.  
  93.  
  94. int winlist_getCount ()
  95.     {
  96.     return ListStats.nWindows;
  97.     }
  98.  
  99.  
  100. HWINFO winlist_getWinfo ()
  101.     {
  102.     return ListStats.hWinfo;
  103.     }
  104.  
  105.  
  106. void winlist_destroy ()
  107.     {
  108.     GlobalFree (ListStats.hWinfo);
  109.     }
  110.